<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>POST Request Example</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            text-align: center;
        }
        h1 {
            color: #333;
        }
        h3 {
            color: #666;
            margin-top: 10px;
        }
        input[type="text"] {
            width: 80%;
            padding: 10px;
            margin: 20px 0;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        button {
            padding: 10px 20px;
            background-color: #007BFF;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
        #response {
            margin-top: 20px;
            font-size: 1.2em;
            color: #333;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>人工智能</h1>
    <h3>madeBy玺朽</h3>
    <input type="text" id="userContent" placeholder="输入内容">
    <button onclick="sendMessage()">发送</button>
    <p id="response"></p>
</div>

<script>
    async function sendMessage() {
        const userContent = document.getElementById('userContent').value;
        document.getElementById('response').innerText = '思考中...';
        document.getElementById('userContent').value ='';
        const response = await fetch('http://localhost:8080/user/talk', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            body: `userContent=${encodeURIComponent(userContent)}`
        });

        const data = await response.json();
        document.getElementById('response').innerText = data.data;
    }
</script>
</body>
</html>